/*
 *  Ball.cpp
 *  CV_Game
 *
 *  Created by Daniel Brümmel on 21.05.11.
 *  Copyright 2011 __MyCompanyName__. All rights reserved.
 *
 */

#include "Ball.h"
#include <opencv/OpenCV.h>
#include <time.h>

Ball::Ball(int maxWidht){
	/* generate secret number: */
	this->setXY(rand() % (maxWidht - 20), 0);
	this->setMovement( rand() % 3 +1 );
}

void Ball::setXY(float x, float y){
	this->x = x;
	this->y = y;
}

void Ball::setX(float x){
	this->x = x;
}

void Ball::setY(float y){
	this->y = y;
}

float Ball::getX(){
	return this->x;
}

float Ball::getY(){
	return this->y;
}

void Ball::setMovement(int m){
	this->movement = m;
}

void Ball::move(){
	this->y += this->movement;
}

void Ball::draw(IplImage *img){
	
 	cvCircle(img, cvPoint( (int) this->x, (int) this->y ), 20, cvScalar(0,255,0,0), 2, 5, 0);
}

bool Ball::chkCollission(CvPoint lu, CvPoint rl){
		
	if( lu.x <= this->x && rl.x >= this->x &&
	    lu.y <= this->y && rl.y >= this->y
	   ){
		return true;
	}
	return false;
}